<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="/common/taglibs.jsp" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>系统管理</title>
    <link href="${cdnctx}/dep/jquery/jquery-ui-1.10.2.custom.css" rel="stylesheet" type="text/css"/>
    <%@ include file="/common/util.jsp" %>
    <script type="text/javascript">
        var deviceAirCodes = [];
        //空调的自动填充
        var deviceAirCodes = eval('${deviceAirInfo }');
        //控制空调的删除
        $(function () {

        });
        function deltr() {
            $(".ligthTr tr:gt(1):last").remove();
            $(".ligthTr tr:gt(1):last").remove();
        }
        function lightAutoComplete() {
            $("input[name='collectAreaItemAirs.airCode']").autocomplete({
                source: deviceAirCodes,
                minLength: 0
            });
            //点击空调输入框则自动弹出列表
            $("input[name='collectAreaItemAirs.airCode']").focus(function () {
                $(this).autocomplete('search');
            });
        }
        $(document).ready(function () {
            //网关的自动填充
            var gateways = eval('${gatewayInfo }');
            $("#gatewayid").autocomplete({
                source: gateways,
                minLength: 0
            });
            $("#gatewayid").focus(function () {
                $(this).autocomplete('search');
            });
            //设备的自动填充
            var sensorIds = [];
            for (var i = 1; i < 9; i++) {
                sensorIds.push(i + '');
            }
            $("#sensorid").autocomplete({
                source: sensorIds,
                minLength: 0
            });
            $("#sensorid").focus(function () {
                $(this).autocomplete('search');
            });
            //通道的自动填充
            var channeIds = [];
            for (var i = 177; i < 185; i++) {
                channeIds.push(i + '');
            }
            $("#channelid").autocomplete({
                source: channeIds,
                minLength: 0
            });
            $("#channelid").focus(function () {
                $(this).autocomplete('search');
            });

            var lightCodeHtml = "<tr>" +
                    "<td class='mainText'>" +
                    "<label class='formlabel'>" +
                    "<font color='red'>*</font>空调：</label>" +
                    "</td>" +
                    "<td>" +
                    "<input type='hidden' name='collectAreaItemAirs.id' value='' />" +
                    "<input type='text' name='collectAreaItemAirs.airCode' value='' class='form_input large' '>&nbsp;" +
                    "<font color='red'>*</font>数量：" +
                    "<input class='form_input' name='collectAreaItemAirs.airnum' value='' type='text' style='width:50px' />&nbsp;" +
                    "</td>" +
                    "<td width='91'>" +
                    "<button type='button' class='form_area_del_btn' onclick='deltr();'>删除</button>" +
                    "</td>" +
                    "</tr>";
            $("#addtr").click(function () {
                $(".ligthTr").append(lightCodeHtml);
                lightAutoComplete();
            });
            //空调自动完成
            lightAutoComplete();

            //是否判断
            $("#addCollectAreaForm").validate({
                // debug: true,
                rules: {
                    'customerinfoid': {
                        required: true,
                    },
                    'gatewayid': {
                        required: true,
                    },
                    'sensorid': {
                        required: true,
                    },
                    'channelid': {
                        required: true,
                    },
                },
                messages: {
                    'customerinfoid': {
                        required: "所属公司",
                    },
                    'gatewayid': {
                        required: "网关ID",
                    },
                    'sensorid': {
                        required: "设备ID",
                    },
                    'channelid': {
                        required: "通道ID",
                    },
                },
                submitHandler: function (form) {
                    $("input[name='collectAreaItemAirs.id']").each(function (i) {
                        $(this).attr("name", "collectAreaItemAirs[" + i + "].id");
                    });
                    $("input[name='collectAreaItemAirs.airCode']").each(function (i) {
                        $(this).attr("name", "collectAreaItemAirs[" + i + "].airCode");
                    });
                    $("input[name='collectAreaItemAirs.airnum']").each(function (i) {
                        $(this).attr("name", "collectAreaItemAirs[" + i + "].airnum");
                    });
                    form.submit();
                }
            });
            $("input[name='collectAreaItemAirs.airCode']").rules("add", {
                required: true,
                messages: {
                    required: "空调"
                }
            });
            $("input[name='collectAreaItemAirs.airnum']").rules("add", {
                required: true,
                messages: {
                    required: "空调数量"
                }
            });
        });
    </script>
</head>
<body class="main">
<div class="-frame -style -luster" id="css_container">
    <!--首页框架页眉部分↓-->
    <%@ include file="/WEB-INF/pages/inc/header.jsp" %>
    <!--首页框架页眉部分↑-->
    <div class="content">
        <!-- Left导航菜单◎开始 -->
        <%@ include file="/WEB-INF/pages/inc/leftmenu.jsp" %>
        <!-- Left导航菜单◎结束 -->
        <div class="main-mid">
            <div class="pos"><img src="${cdnctx}/src/index/img/index.png"><a href="<%--${cdnctx}/system/systemMenu.shtml--%>">系统管理
                ></a><a href="${cdnctx}/systemCollectAreaAir/collectAreaAirList.shtml">采集区域管理</a><a>> <c:if
                    test="${empty collectArea.id }">添加</c:if><c:if test="${not empty collectArea.id }">编辑</c:if>采集区域</a>
            </div>
            <div class="css_contentDiv">
                <div class="searchDetailed">
                    <form id="addCollectAreaForm" method="post"
                          action="${cdnctx}/systemCollectAreaAir/saveCollectAreaAir.shtml">
                        <input type="hidden" name="id" id="id" value="${collectArea.id}"/>
                        <table align="center" id="table" width="800" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td class="mainText"><label class="formlabel"><font color="red">*</font>所属公司：</label>
                                </td>
                                <td>
                                    <select id="customerinfoid" name="customerinfoid" class="form_select large">
                                        <option value=''>--请选择--</option>
                                        <c:forEach items="${companyList}" var="entity">
                                            <option value="${entity.id}"
                                                    <c:if test="${entity.id==collectArea.customerinfoid}">selected</c:if>>${entity.customername}</option>
                                        </c:forEach>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td class="mainText"><label class="formlabel"><font color="red">*</font>网关ID：</label>
                                </td>
                                <td>
                                    <input type="text" class="form_input large" name="gatewayid" id="gatewayid"
                                           value="${collectArea.gatewayid}"/>
                                </td>
                            </tr>
                            <tr>
                                <td class="mainText"><label class="formlabel"><font color="red">*</font>设备ID：</label>
                                </td>
                                <td>
                                    <input type="text" class="form_input large" name="sensorid" id="sensorid"
                                           value="${collectArea.sensorid}" maxlength="40"/>
                                </td>
                            </tr>

                            <tr>
                                <td class="mainText"><label class="formlabel"><font color="red">*</font>通道ID：</label>
                                </td>
                                <td>
                                    <input type="text" class="form_input large" name="channelid" id="channelid"
                                           value="${collectArea.channelid}" maxlength="40"/>
                                </td>
                            </tr>

                            <tr>
                                <td class="mainText"><label class="formlabel">采集区域名：</label></td>
                                <td>
                                    <input type="text" class="form_input large" id="collectareaname"
                                           name="collectareaname" value="${collectArea.collectareaname}" maxlength="100"
                                           onblur="" onmouseout=""/>
                                </td>
                            </tr>

                            <tr>
                                <td class="mainText"><label class="formlabel">备注：</label></td>
                                <td>
                                    <input type="text" class="form_input large" id="memo" name="memo"
                                           value="${collectArea.memo}" maxlength="500" onblur="" onmouseout=""/>
                                </td>
                            </tr>
                            <tbody class="ligthTr">
                            <c:if test="${not empty(collectAreaItemAirs) }">
                                <c:forEach items="${collectAreaItemAirs}" var="entity" varStatus="status">
                                    <tr>
                                        <td class="mainText"><label class="formlabel"><font
                                                color="red">*</font>空调：</label></td>
                                        <td>
                                            <input type="hidden" name="collectAreaItemAirs.id" value="${entity.id }"/>
                                            <input type="text" name="collectAreaItemAirs.airCode"
                                                   value="${entity.airCode }" class="form_input large">
                                            <font color="red">*</font>数量：<input class="form_input"
                                                                                name="collectAreaItemAirs.airnum"
                                                                                value="${entity.airnum }" type="text"
                                                                                style="width:50px"/>&nbsp;
                                        </td>
                                        <td width="91">
                                            <button type="button" class="form_area_del_btn" onclick="deltr();">删除
                                            </button>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:if>
                            <c:if test="${empty(collectAreaItemAirs) }">
                                <tr>
                                    <td class="mainText"><label class="formlabel"><font color="red">*</font>空调：</label>
                                    </td>
                                    <td>
                                        <input type="hidden" name="collectAreaItemAirs.id" value=""
                                                ><input type="text" name="collectAreaItemAirs.airCode" value=""
                                                        class="form_input large">
                                        <font color="red">*</font>数量：<input class="form_input"
                                                                            name="collectAreaItemAirs.airnum" value=""
                                                                            type="text" style="width:50px"/>&nbsp;
                                    </td>
                                    <td width="91">
                                        <button type="button" class="form_area_del_btn" onclick="deltr();">删除</button>
                                    </td>
                                </tr>
                            </c:if>
                            </tbody>
                            <tr>
                                <td></td>
                                <td>
                                    <button id="addtr" class="form_area_add_btn" type="button">新增</button>
                                </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td>
                                    <input type="submit" class="form_save" value="保&nbsp;存"/>
                                    <input type="reset" class="form_cancle" value="取&nbsp;消"/>
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
            </div>
        </div>

    </div>

    <!--首页框架页尾部分↓-->
    <%@ include file="/WEB-INF/pages/inc/footer.jsp" %>
    <!--首页框架页尾部分↑-->
</div>
</body>
</html>